<?php

namespace App\Http\Controllers\Admin;

use App\Models\Admin\Users;
use Illuminate\Http\Request;

class UsersController extends BaseController
{
    /**
     * 首页
     * @param Request $request
     */
    public function getList(Request $request)
    {
        $params = $_GET;
        $params['limit'] = $request->input('limit', $this->limit_arr[0]);
        $list = Users::getList($params);
        $data['items'] = $list;
        $data['keywords'] = isset($params['keywords']) ? "keywords={$params['keywords']}" : null;
        return view('Admin/Users/get_list', $data);
    }

    /**
     * 更改状态
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function changeStatus(Request $request)
    {
        $request->validate([
            'id' => 'required',
            'status' => 'required', // 状态1: 启用, 2: 禁用
        ]);
        $params = $_POST;
        $save = Users::changeStatus($params);
        return response()->json($save);
    }

    /**
     * 删除
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function delete(Request $request)
    {
        $request->validate([
            'id' => 'required',
        ]);
        $params = $_POST;
        $save = Users::del($params);
        return response()->json($save);
    }
}